/** Unit test program to test the EventProcessor and Messaging capablities */

// how many generators are started
//#define NUM_GENERATORS 20

#define NUM_DECRYPTERS 10
#include <unistd.h>
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>

#include "Controller.h"
#include "Decrypter.h"
#include "DistributedCounter.h"
#include "TwoWayList.cc"

int main(void){
  // create and start the adder
  Controller controller;
  controller.ForkAndSpin(); // starts one independent thread for the adder

  // the counter to detect when all the generators finished
  DistributedCounter dCounter(NUM_DECRYPTERS);

  // start the generators
  TwoWayList <EventProcessor> myDecrypters;
  for (int i=0; i<NUM_DECRYPTERS; i++) {
    Decrypter newDecrypter(controller, dCounter);
    newDecrypter.ForkAndSpin();
    myDecrypters.Insert(newDecrypter);
  }
  
  // the thread running the main program is still available
  // we block it until the adder dies
  controller.WaitForProcessorDeath();  

//  printf("The correct result is: %d\n", REPETITIONS*(REPETITIONS-1)/2*NUM_GENERATORS);
  
  // adder and all the generator automatically destroyed

  return 0;
}
